<template>
	<om-addpage :menuName="menuName" :busCode="busCode" @formSubmit="formSubmit" :showHistoryBtn="false" saveBtnText="确认" :customAddFunc="true">
		<om-sub title="审核打分" subTitle="请拖动滑块打分">
			<uni-list v-for="(item,index) in datas" :index="index" :key="index">
				<uni-list-item  :showArrow="false" :showHover="false">
					<view><om-label :label="item.interviewElementName + '(分值：'+item.score+')'" ></om-label></view>
					<view>
						<slider :max="item.score" block-color="#8A6DE9" block-size="26"  :value="0" @change="sliderChange" show-value :data-index="index" step="1" />
					</view>
				</uni-list-item>
			</uni-list>
		</om-sub>
	</om-addpage>
</template>

<script>
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
export default {
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return {
			formdata: {
			},
			sliderData:[],
			datas:[],
			itemIdList:[],
			menuName: '',
			formId:"",
			busCode: ''
		};
	},
	computed: {
		...mapState(useLoginUserStore, ['orgId'])
	},
	methods: {
		/**
		 * 打分
		 */
		sliderChange(e) {
			var index = e.currentTarget.dataset.index
			var score = e.detail.value
			this.$set(this.sliderData[index],'examineScore',score)
		},
		formSubmit: function(formdata) {
			let _that = this;
			_that.om.request("trecruitAgencyInterviewEvaluate/doAudited",{
				isApprove:1,
				formId:this.formId,
				businessFormCode:this.busCode,
				objStr:JSON.stringify(this.sliderData)
			}).then(res=>{
				if(res.succeed){
					_that.om.getFormInfo(_that.formId, _that.busCode, true)
				}else{
					_that.om.toast(res.msg)
				}
			})
		},
	},
	onLoad: function(options) {
		let _that = this;
		_that.menuName = options.title || '审核打分';
		uni.setNavigationBarTitle({
			title: _that.menuName
		});
		if(options.code){
			_that.busCode = options.code
		}else{
			_that.om.toast("没有表单编码")
		}
		if(options.fileId){
			_that.formId = options.fileId
		}else{
			_that.om.toast("没有表单ID")
		}
		_that.om.request("trecruitAgencyInterviewEvaluate/examineTable",{
			code: _that.busCode,
			formId:_that.formId
		}).then(res=>{
			if(res.succeed){
				if(res.value){
					_that.datas = res.value.body
					_that.itemIdList = res.value.itemId
					for(let index in _that.datas){
						this.sliderData.push({
							formCode: this.busCode,
							formId: this.formId,
							interviewElementId: _that.itemIdList[index],
							examineScore: 0
						})
					}
				}
			}else{
				_that.om.toast(res.msg)
			}
		})
	}
};
</script>

<style></style>
